<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>

		<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
		<style>
			#loginForm {
				
				background-color: lightblue;
				width: 300px;
				margin: 200px auto;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<div id="loginForm" v-if="!isLogin">
				<h1 style="text-align: center;">用户登录</h1>
				<div>用户名:<input type="text" v-model="username" /></div>
				<div>密码:<input type="password" v-model="password"/></div>
				<div><button @click="login">登录</button></div>
			</div>
			<div v-else>
				{{username}}已登录<br />
				<div><button @click="loginOut">登出</button></div>
			</div>
		</div>

			

		<script>
			var app = Vue.createApp({
				data() {
					return {
						username:'',
						password:'',
						isLogin: false
					}
				},
				methods:{
					login:function(){
						if(this.username == "admin" && this.password == "123")
						{
							alert("登录成功")
							this.isLogin = true
						}
						else{
							alert("登录失败")
						}
					},
					loginOut: function(){
						this.isLogin = false;
					}
				}
			});
			var vm = app.mount("#app")
		</script>



	</body>
</html>